<?php
/**
 * 加载sdk包以及错误代码包
 */
require_once '../sdk.class.php';
//require_once dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'error.class.php';

$oss_sdk_service = new ALIOSS();

/**
 * 获取bucket列表,该方法主要获取该账户下所有的bucket列表
 * 使用方法如下：
 * $bucket_list = $oss_sdk_service->list_bucket();
 */
//$bucket_list = $oss_sdk_service->list_bucket();
//echo "<p>获取bucket列表</p>";
//print_r($bucket_list);
//echo "<p></p>";

/**
 * 获得指定bucket的ACL
 * 调用方法如下：
 * $get_bucket_acl = $oss_sdk_service->get_bucket_acl($bucket);
 * 其中需要传入的参数为 某一$bucket的名称
 */
//获取指定bucket的ACL
//$bucket = 'aaaaaaaaaaa';
//$options = array(
//	'Content-Type' => 'text/xml',
//);
//$get_bucket_acl = $oss_sdk_service->get_bucket_acl($bucket,$options);
//echo "<p>获取bucket的ACL</p>";
//print_r($get_bucket_acl);
//echo "<p></p>";


/**
 * 设置指定bucket的ACL,目前只有三种acl private,public-read,public-read-write
 * 调用方法如下：
 * $set_bucket_acl = $oss_sdk_service->set_bucket_acl($bucket, $acl);
 * 其中需要指定$bucket,以及$acl的值,$acl的取值只能是private,public-read,public-read-write其中之一
 */
//设置指定bucket的ACL,目前只有三种acl private,public-read,public-read-write
//$bucket = 'mybucket0001';
//$acl = 'public-read';
//$set_bucket_acl = $oss_sdk_service->set_bucket_acl($bucket, $acl);
//echo "<p>设置bucket的ACL</p>";
//print_r($set_bucket_acl);
//echo "<p></p>";

/**
 * 创建bucket
 * 调用方法如下：
 * $create_bucket = $oss_sdk_service->create_bucket($bucket, $acl);
 * 其中需要传入$bucket,$acl是可选的，如果不指定ACL，则默认会是private,
 * $acl的取值只能是private,public-read,public-read-write其中之一
 */
//创建bucket
//$bucket = 'mybucket0001';
//$acl = 'public-read';
//$create_bucket = $oss_sdk_service->create_bucket($bucket, $acl);
//echo "<p>创建bucket</p>";
//print_r($create_bucket);
//echo "<p></p>";


/**
 * 删除bucket
 * 调用方法如下：
 * $delete_bucket = $oss_sdk_service->delete_bucket($bucket);
 * 需要传入$bucket参数
 */
//删除bucket
//$bucket = 'mybucket0001';
//$delete_bucket = $oss_sdk_service->delete_bucket($bucket);
//echo "<p>删除bucket</p>";
//print_r($delete_bucket);
//echo "<p></p>";

/**
 * 获得bucket下的object列表
 * 调用方法如下：
 * $list_object = $oss_sdk_service->list_object($bucket,$options);
 * 其中需要传入$bucket参数,$options为可选参数，如果需要传入$options,必须为数组，其中数据的key必须为指定的，否则参数无效
 * $options = array(
 * 		'max-keys' 	=> max-keys用于限定此次返回object的最大数，如果不设定，默认为100，max-keys取值不能大于100。
 * 		'prefix'	=> 限定返回的object key必须以prefix作为前缀。注意使用prefix查询时，返回的key中仍会包含prefix。
 * 		'delimiter' => 是一个用于对Object名字进行分组的字符。所有名字包含指定的前缀且第一次出现delimiter字符之间的object作为一组元素
 * 		'marker'	=> 用户设定结果从marker之后按字母排序的第一个开始返回。
 * )
 * 其中 prefix，marker用来实现分页显示效果，参数的长度必须小于256字节。
 */
////获得bucket下的object列表
//$bucket = 'aaaaaaaaaaa';
//$options = array(
//	'delimiter' => '/',
//	'prefix' => '',
	//'max-keys' => 10,
//	'marker' => 'fff/',
//);
//$list_object = $oss_sdk_service->list_object($bucket,$options);
//echo "<p>获取Object列表</p>";
//print_r($list_object);
//echo "<p></p>";


/**
 * 获得$bucket下的某个object,$object为文件，不能为目录
 * 调用方法如下：
 * $get_object = $oss_sdk_service->get_object($bucket,$object);
 * 其中需要传入$bucket,$object参数，参数为必须
 */
//获得bucket下的object
//$bucket = 'mybucket0001';
//$object = 'object0003/31天反射.pdf';
//$get_object = $oss_sdk_service->get_object($bucket,$object);
//echo "<p>获取Object</p>";
//print_r($get_object);
//echo "<p></p>";


/**
 * 创建文件夹(是虚拟文件夹)
 * 调用方法如下：
 * $create_object_dir = $oss_sdk_service->create_object_dir($bucket,$object);
 * 其中需要传入$bucket,$object参数，参数为必须
 */
//创建文件夹(是虚拟文件夹)
//$bucket = 'mybucket0001';
//$object = 'object0003';
//$create_object_dir = $oss_sdk_service->create_object_dir($bucket,$object);
//echo "<p>创建文件夹</p>";
//print_r($create_object_dir);
//echo "<p></p>";


/**
 * 通过http body上传文件
 * 调用方法如下：
 * $upload_file_by_content = $oss_sdk_service->upload_file_by_content($bucket,$object,$upload_file_options);
 * 其中的$bucket,$object以及$upload_file_options为必选参数，$upload_file_options必须为数组，且key必须为规定的值，否则会上传失败
 * 其中的content 为文件的内容，$length为文件的大小
 * $upload_file_options = array(
 *	'content' => $content,
 *	'length' => $length,
 * );
 */
//通过http body上传文件
//$bucket = 'aaaaaaaaaaa';
//
//$filename = '31天反射.pdf';
//$file = "D:\\Book\\silverlight\\".$filename;
//$file = iconv("UTF-8", "GBK", $file); 

//$object = 'object0003/'.$filename;
//$content = '';
//$length = 0;
//$fp = fopen($file,'r');
//if($fp){
//	$f = fstat($fp);
//	$length = $f['size'];
//	while(!feof($fp)){
//		$content .= fgets($fp,8192);
//	}
//}
//$upload_file_options = array(
//	'content' => $content,
//	'length' => $length,
//);
//var_dump($upload_file_options);exit;
//$upload_file_by_content = $oss_sdk_service->upload_file_by_content($bucket,$object,$upload_file_options);
//echo "<p>通过http body上传文件</p>";
//print_r($upload_file_by_content);
//echo "<p></p>";


/**
 * 检测Object是否存在
 * 调用方法如下：
 * $is_object_exist = $oss_sdk_service->is_object_exist($bucket, $object);
 * 其中需要传入$bucket,$object参数，参数为必须
 */
//检测Object是否存在
//$bucket = 'mybucket0001';
//$object = 'object';
//$is_object_exist = $oss_sdk_service->is_object_exist($bucket, $object);
//echo "<p>Object是否存在</p>";
//var_dump($is_object_exist?'存在':'不存在');
//echo "<p></p>";


/**
 * 获得某一个object的URL
 * 调用方法如下：
 * $get_object_url = $oss_sdk_service->get_object_url($bucket, $object);
 * 其中需要传入$bucket,$object参数，参数为必须,$object为文件
 */
//获得Object url
//$bucket = 'mybucket0001';
//$object = 'object0003/31天反射.pdf';
//$get_object_url = $oss_sdk_service->get_object_url($bucket, $object);
//echo "<p>获得Object URL</p>";
//var_dump($get_object_url?$get_object_url:'不存在');
//echo "<p></p>";


/**
 * 获得object的meta
 * 调用方法如下：
 * $get_object_meta = $oss_sdk_service->get_object_meta($bucket, $object);
 * 其中需要传入$bucket,$object参数，参数为必须,如果object为文件夹，则需要添加'/'
 */
//获得object下的meta
//$bucket = 'mybucket0001';
//$object = 'object0003/';
//$get_object_meta = $oss_sdk_service->get_object_meta($bucket, $object);
//echo "<p>获取Object Meta</p>";
//print_r($get_object_meta);
//echo "<p></p>";


/**
 * 删除object
 * 调用方法如下：
 * $delete_object = $oss_sdk_service->delete_object($bucket,$object);
 * 其中需要传入$bucket,$object参数，如果object为文件，则会直接删除，如果为文件夹，若文件夹不为空，则不能删除
 */
//删除object
//$bucket = 'mybucket0001';
//$object = 'object';
//$delete_object = $oss_sdk_service->delete_object($bucket,$object);
//echo "<p>删除object</p>";
//print_r($delete_object);
//echo "<p></p>";

/**
 * 创建object group
 * 调用方法如下：
 * $create_object_group = $oss_sdk_service->create_object_group($bucket,$object_group,$object_group_array);
 * 其中参数$object_group,$bucket,$object_group_array不为空，且$object_group_array内的object必须位于同一bucket下
 */
//创建object group
//$bucket = 'mybucket0001';
//$object_group_array = array(
//	'SVN.txt',
//	'vpn.txt',
//	'QC.txt',
//);
//$object_group = 'object_group_002';
//$create_object_group = $oss_sdk_service->create_object_group($bucket,$object_group,$object_group_array);
//echo "<p>创建object group</p>";
//print_r($create_object_group);
//echo "<p></p>";


/*
 * 获取object group
 * 调用方法如下：
 * $get_object_group = $oss_sdk_service->get_object_group($bucket,$object_group);
 * 其中参数$object_group,$bucket为必须参数
 */
//获取object group
//$bucket = 'mybucket0001';
//$object_group = 'object_group_002';
//$get_object_group = $oss_sdk_service->get_object_group($bucket,$object_group);
//echo "<p>获取object group</p>";
//print_r($get_object_group);
//echo "<p></p>";


/**
 * 获取object group index 
 * 调用方法如下：
 * $get_object_group_index = $oss_sdk_service->get_object_group_index($bucket,$object_group);
 * 其中参数$object_group,$bucket为必须参数
 */
//获取object group index
//$bucket = 'mybucket0001';
//$object_group = 'object_group_002';
//$get_object_group_index = $oss_sdk_service->get_object_group_index($bucket,$object_group);
//echo "<p>获取object group index</p>";
//print_r($get_object_group_index);
//echo "<p></p>";


/**
 * 获取object group meta
 * 调用方法如下：
 * $get_object_group_meta = $oss_sdk_service->get_object_group_meta($bucket,$object_group);
 * 其中参数$object_group,$bucket为必须参数
 */
//获取object group meta信息
//$bucket = 'mybucket0001';
//$object_group = 'object_group_002';
//$get_object_group_meta = $oss_sdk_service->get_object_group_meta($bucket,$object_group);
//echo "<p>获取object group meta</p>";
//print_r($get_object_group_meta);
//echo "<p></p>";


/**
 * 删除object group 
 * 调用方法如下：
 * $delete_object_group = $oss_sdk_service->delete_object_group($bucket,$object_group);
 * 其中参数$object_group,$bucket为必须参数
 */
//删除object Group
//$bucket = 'mybucket0001';
//$object_group = 'object_group_002';
//$delete_object_group = $oss_sdk_service->delete_object_group($bucket,$object_group);
//echo "<p>删除object group</p>";
//print_r($delete_object_group);
//echo "<p></p>";








